<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "/resource/datagrid"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.filter = $('#search_key').val() : ''
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"mDataProp" : "Id","sTtile" : "ID", "bSortable": false}
			,{"mDataProp" : "Name","sTtile" : "ID", "bSortable": false}
			,{   
				"mDataProp": "UrlFor",  
				"bSortable": false,
				"render": function ( data, type, full, meta ) {  
					return '<a href="/'+data+'">' + data + '</a>';  
				}  
			 } 
			,{   
				"mDataProp": "Icon",  
				"bSortable": false,
				"render": function ( data, type, full, meta ) { 
					return '<i class="'+ data +'"></i>'
				}  
			 } 
			 ,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) { 
					btns = '<a class="am-btn am-btn-secondary am-btn-xs" href="/resource/edit/'+ full.Id +'">编辑</a>';
					btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="delResource('+ full.Id +');return false;">删除</a>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
	
	function delResource(id) {
		layer.confirm('确定要删除所选记录吗？删除后不可恢复！', function(index){
			$.post('{{ urlfor "ResourceController.Delete"}}', {Id:id}, function(res){
				if(res.code == 1) {
					layer.msg(res.msg)
				} else {
					tables.ajax.reload();
				}
				layer.close(index);
			}, 'json');
		});
	}
	
</script>